package fx.sample;

import fx.utils.DESEncoder;
import fx.utils.EncryptUtil;
import javafx.event.ActionEvent;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import org.apache.commons.lang3.StringUtils;

import java.awt.*;

public class project {
    public TextField projectId;
    public TextField encryptedPubKey;
    public TextField userId;
    public TextArea out;
    public HBox item1;

    public void submit(ActionEvent actionEvent) throws Exception {
        String projectIdStr = projectId.getText();
        String encryptedPubKeyStr = encryptedPubKey.getText();
        String userIdStr = userId.getText();
        StringBuilder outStr = new StringBuilder();
        String type = item1.getAccessibleText();
        if (StringUtils.isEmpty(type)) {
            outStr.append("项目ID(key)：" + projectIdStr + " 项目密钥密文(data)：" + encryptedPubKeyStr);
            outStr.append("\n");
            String pubKey = DESEncoder.decode(projectIdStr, encryptedPubKeyStr);
            outStr.append("解密得到项目密钥：" + pubKey);
            outStr.append("\n");
            outStr.append("项目密钥(key)：" + pubKey + " 用户ID(data)：" + userIdStr);
            String userKey = DESEncoder.encode(pubKey, userIdStr);
            outStr.append("\n");
            outStr.append("加密得到用户密钥：" + userKey);
        } else if ("2".equals(type)) {
            outStr.append("项目ID(key)：" + projectIdStr + " 私有云证书秘钥(data)：" + EncryptUtil.getCertificateKey(projectIdStr));
        } else if ("3".equals(type)) {
            outStr.append("项目ID(key)：" + projectIdStr + " 私有云数据库秘钥(data)：" + EncryptUtil.getKeyByProjectId(projectIdStr));
        }
        out.setText(outStr.toString());
    }
}
